package com.app.piemoment.entity;

public class City {
	public String province;
	public String city;
	public String town;

	public City() {
		province = "";
		city = "";
		town = "";
	}

	public City(String ciytString, String split) {
		if (ciytString != null && ciytString.length() > 0) {
			String[] spaceStrings = ciytString.split(" ");
			if (spaceStrings.length > 0 && !spaceStrings[0].equals(null)) {
				province = spaceStrings[0];
				if (spaceStrings.length > 1 && !spaceStrings[1].equals(null)) {
					city = spaceStrings[1];
					if (spaceStrings.length > 2
							&& !spaceStrings[2].equals(null)) {
						town = spaceStrings[2];
					}
				}
			}
		} else {
			province = "";
			city = "";
			town = "";
		}
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getTown() {
		return town;
	}

	public void setTown(String town) {
		this.town = town;
	}

	public String cityToString(String split) {
		StringBuffer sBuffer = new StringBuffer();
		sBuffer.append(province);
		if (city != null && city.length() > 0 && province != city) {
			sBuffer.append(split).append(city);
			if (town != null && town.length() > 0 && town != city) {
				sBuffer.append(split).append(town);
			}
		}
		return sBuffer.toString();
	}

	public String getLastSpace() {
		String spaceString = province;
		if (town != null && town.length() > 0) {
			spaceString = town;
		} else if (city != null && city.length() > 0) {
			spaceString = city;
		} else {
			spaceString = province;
		}
		return spaceString;
	}
}
